const connect = require('connect')
const url = require('url')

const api = connect()
  .use((req, res) => {
    foo()
    res.end('ok')
  })
  .use((err, req, res, next) => {
    res.end('[api] Error: ' + err)
  })

const app = connect()
  .use((req, res, next) => {
    const path = url.parse(req.url).pathname

    if (path === '/api') {
      next()
      return
    }

    bar()

    next()
  })
  .use(api)
  .use((err, req, res, next) => {
    res.end('[app] Error: ' + err)
  })
  .listen(3000)


/*
http://localhost:3000/
http://localhost:3000/api
 */
